#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <iostream> 
#include <string>

int main(int argc, char *argv[])
{
	
	FILE* pInputFile = fopen ("C:\\1080i.mpg", "rb");
	if (pInputFile == NULL){exit (-1);}
	FILE* pOutputFile = fopen ("C:\\1080i_with errors_200.mpg", "wb");
	if (pOutputFile == NULL){exit (-1);}
	
	/* initialize random seed: */
	srand ( time(NULL) );

	char cBuffer[500];
	int nLength;

	while ((nLength = fread(cBuffer, 1, 500, pInputFile)) > 0)
	{
		int nSecret = rand() % 200 + 1;
		for (int i=0; i< nLength; i++)
		{
			if (nSecret == 30)
				cBuffer[i] = (cBuffer[i] == 0)? 1:0;
		}
		fwrite(cBuffer, 1, 500, pOutputFile);
	}
}